package org.luxor.commons.zookeeper.watcher;

import org.apache.curator.framework.recipes.cache.NodeCacheListener;
import org.luxor.commons.zookeeper.annotation.ZookeeperWatcher;
import org.luxor.commons.zookeeper.client.ZookeeperClient;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@ZookeeperWatcher(value = NodeWatcher.PATH)
public class NodeWatcher implements NodeCacheListener {
    public static final String PATH = "/watcher";

    @Resource
    private ZookeeperClient zookeeperClient;

    @Override
    public void nodeChanged() {
        System.out.println("==========NodeWatcher start==============");
        System.out.println("NodeWatcher data: " + zookeeperClient.getDataStr(NodeWatcher.PATH));
        System.out.println("==========NodeWatcher end==============");
    }
}